<template>
  <!--  全部字体加大一号，白色背景，垂直居中，子元素宽度占满-->
  <!--  过来的授权及时手机号授权，也会提示先登录，可以自己选择手机号登陆-->
  <div class="h100p bg-white col-all-center flex-col">

    <button @click="platformLoginClick" class="mt-lg mb">授权登陆</button>
    {{phoneNum}}
    <button @click="platformPhoneClick" class="mt-lg mb">授权手机号</button>
    <button @click="cleardata" class="mb">清空数据</button>
    <button @click="getUserAndTalks">获取用户和动态</button>

    <view v-if="user">登录了，昵称：{{ user.nickname }}</view>
    <view v-if="user">性别：{{ user.gender }}</view>

    <view v-if="talks.length" class="flex-1 overflow-auto">
      <view v-for="talk in talks">
        <view>
          {{ talk.user.nickname }}
        </view>
        <view>
          {{ talk.content }}
        </view>
        <view>
          {{ talk.updateTime }}
        </view>
      </view>
    </view>
  </div>
</template>

<script lang="ts">
import {Vue, Component} from 'vue-property-decorator'
import UserVO from '@/model/user/UserVO'
import {namespace} from 'vuex-class'
import UniUtil from '@/utils/UniUtil'
import UCheckbox from 'uview-ui/components/u-checkbox/u-checkbox.vue'
import UButton from 'uview-ui/components/u-button/u-button.vue'
import {systemModule, userModule} from '@/plugins/store'
import ThreeAuthType from "@/const/ThreeAuthType";
import ButtonOpenType from "@/const/ButtonOpenType";
import Alert from "@/utils/Alert";
import ThreeAuthResultVO from "@/model/ThreeAuthResultVO";
import SocialUniAuthVO from "@/model/SocialUniAuthVO";
import TalkAPI from "@/api/TalkAPI";

const SkipUrlConst = {}

const userStore = namespace('user')
const configStore = namespace('config')
const systemStore = namespace('system')

@Component({
  components: {
    UCheckbox, UButton
  }
})
export default class LoginVue extends Vue {
  @userStore.State('user') user: UserVO
  @userStore.State('phoneNum') phoneNum: string
  // @configStore.Getter(ConfigMap.authCodeIntervalKey) authCodeInterval: number
  // @configStore.Getter(ConfigMap.qqServiceKey) qqService: string
  @systemStore.State('isMp') isMp: boolean

  talks = []

  onLoad() {
    this.getUserAndTalks()
  }

  cleardata() {
    userModule.setUser(null)
    this.talks = []
  }

  getUserAndTalks() {
    userModule.getMineUserAction()
    this.queryTalks()
  }

  queryTalks() {
    // TalkAPI.queryTalksAPI(null, null, null, null, null, null).then((res) => {
    TalkAPI.queryTalksAPI([], [], '首页', '全部', 0, 40).then((res) => {
      this.talks = res.data
    })
  }

  platformLoginClick(loginResult) {
    const authVO: SocialUniAuthVO = new SocialUniAuthVO('user', '10086')
    uni.navigateToMiniProgram({
      appId: 'wx0bf5fe9ceeab514c',
      // appId: '1109985787',
      path: 'pages/user/login',
      extraData: authVO,
      envVersion: 'trial',
      success(res) {
        // 打开成功
      }
    })
  }

  platformPhoneClick(loginResult) {
    const authVO: SocialUniAuthVO = new SocialUniAuthVO('phone', '10086')
    uni.navigateToMiniProgram({
      appId: 'wx0bf5fe9ceeab514c',
      // appId: '1109985787',
      path: 'pages/user/login',
      extraData: authVO,
      envVersion: 'trial',
      success(res) {
        // 打开成功
      }
    })
  }
}
</script>
